# 第一阶段：构建前端
FROM 10.210.10.5:9090/pids_test/nginx:0.0.1 as frontend-builder
WORKDIR /app/frontend
# 直接复制到dist目录
COPY frontend/dist/ /app/frontend/dist/

# 第二阶段：构建最终镜像
FROM 10.210.10.5:9090/pids/alpine:3.20

# 安装必要的软件包
RUN apk update && \
    apk add --no-cache tzdata nginx && \
    cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && \
    echo "Asia/Shanghai" > /etc/timezone

MAINTAINER Huanfion <648890146@qq.com>

# 创建必要的目录
RUN mkdir -p /home/pids/ /usr/share/nginx/html && \
    chmod -R 777 /home/pids/

# 复制前端构建产物
COPY --from=frontend-builder /app/frontend/dist/ /usr/share/nginx/html/

# 复制后端应用和配置文件
ADD pids-cloud-server/main /home/pids/app
COPY pids-cloud-server/application.yml /application.yml
RUN chmod +x /home/pids/app

# 配置Nginx
COPY pids-cloud-server/nginx.conf /etc/nginx/nginx.conf

# 暴露端口
EXPOSE 80 9999 9998 6060


# 启动服务
CMD ["/bin/sh", "-c", "/home/pids/app & nginx -g 'daemon off;'"]

